
package simuri.uridb;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author fomy
 */

public class WordsUriTable {
   
public void wordsUriId(String surfaceformfile){
   
Connection con = DbConnection.getConnection();

try
 {
 BufferedReader br = new BufferedReader(new FileReader(surfaceformfile));
 Statement stmt = con.createStatement();
 String line;
while (( line = br.readLine()) != null )
{
  System.out.println(line);
  String[] split= line.split("\t"); 
  List<String> list = Arrays.asList(split);
  Set<String> set = new HashSet<>(list);
  set.remove(split[0]);
  String[] result = new String[set.size()];
  set.toArray(result);
 String uriname= "http://dbpedia.org/resource/"+split[0];
  System.out.println(uriname);
  for( int j=0;j<result.length;j++){
      String words=result[j].replaceAll("['/]","");
      words = words.replaceAll("\\\\", "");
      String insert ="INSERT INTO words_uris(words,uriname) VALUES('" + words + "','" + uriname + "')";
      stmt.execute(insert);
     }
}
  
   stmt.close();
   con.close();
   }
   catch (SQLException se){
   System.out.println("SQL Fehler "+se.getMessage());
   se.printStackTrace(System.out);
   }catch (FileNotFoundException e) {} 
   catch (IOException e)
  {
   System.out.println("File reading error!");
   }
}
    
}
